'''鼓励金模型'''
from django.db import models

class EncourageActivity(models.Model):
    '''鼓励金活动'''

    IS_ENTER_CHOICES = (
        (1, '初始状态'),
        (2, '全录入'),
        (3, '部分录入'),
        (4, '录入失败')
    )

    PAY_WAY_CHOICES = (
        (1, '微信'),
        (2, '支付宝')
    )

    IS_AUTH_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    IS_KEGUAN_CHOICES = (
        (0, '否'),
        (1, '是')
    )
    id = models.BigIntegerField(verbose_name="活动id", primary_key=True)
    activity_id = models.CharField(verbose_name='活动id', max_length=32, null=True, blank=True)
    name = models.CharField(verbose_name='活动名称', max_length=64)
    user = models.ForeignKey('users.User', verbose_name='关联用户', on_delete=models.CASCADE, null=True, blank=True)
    file = models.FileField(verbose_name='文件',null=True, blank=True)
    remark = models.TextField(verbose_name='录入说明', null=True, blank=True)
    create_time = models.DateTimeField(verbose_name='添加时间', null=True, blank=True)
    is_enter = models.SmallIntegerField(verbose_name='状态', choices=IS_ENTER_CHOICES, default=1)
    max_coupons = models.IntegerField(verbose_name='总数', default=0)
    entry_coupons = models.IntegerField(verbose_name='录入数', default=0)
    coupons = models.IntegerField(verbose_name='领取数', default=0)
    pay_way = models.SmallIntegerField(verbose_name='派发平台', choices=PAY_WAY_CHOICES, null=True, blank=True)
    is_auth = models.SmallIntegerField(verbose_name='是否认证', choices=IS_AUTH_CHOICES, null=True, blank=True)
    destroy_user = models.ForeignKey('users.User', verbose_name='操作人', on_delete=models.SET_NULL, null=True, blank=True, related_name='destroy_user_set')
    channel = models.ForeignKey('activities.Channel', verbose_name='派发平台', on_delete=models.SET_NULL, null=True, blank=True)
    publish_start_time = models.DateTimeField(verbose_name='发放开始时间', null=True, blank=True)
    publish_end_time = models.DateTimeField(verbose_name='发放开始时间', null=True, blank=True)
    level = models.ForeignKey('users.Level', verbose_name='所属机构', on_delete=models.SET_NULL, null=True, blank=True)
    is_keguan = models.SmallIntegerField(verbose_name='是否推送客管系统', choices=IS_KEGUAN_CHOICES, default=0)
    pushEventIds = models.CharField(verbose_name='营销事件ID', max_length=256, null=True, blank=True)

    class Meta:
        db_table = 'tb_m_encourage_activity'
        verbose_name = '鼓励金活动'
        verbose_name_plural = verbose_name


class EncourageDraw(models.Model):
    '''抽奖资格'''

    PAYMENT_STATUS_CHOICES = (
        (0, '审核中'),
        (1, '未领取'),
        (2, '已领取'),
        (3, '领取失败'),
        (4, '已撤销'),
        (5, '已过期'),
        (6, '派发中'),
        (7, '退票/取消')
    )

    PAYMENT_TYPE_CHOICES = (
        (1, '微信'),
        (2, '支付宝')
    )

    PAY_WAY_CHOICES = (
        (1, '微信'),
        (2, '支付宝')
    )
    id = models.BigIntegerField(verbose_name="派发明细id", primary_key=True)
    business_no = models.CharField(verbose_name='商户号', max_length=32)
    amount = models.DecimalField(verbose_name='总金额', max_digits=10, decimal_places=2, default=0)
    partner_trade_no = models.CharField(verbose_name='商户订单号', max_length=32)
    desc = models.CharField(verbose_name='备注', max_length=100)
    payment_no = models.CharField(verbose_name='支付订单号', max_length=64, null=True, blank=True)
    payment_time = models.DateTimeField(verbose_name='领取时间', null=True, blank=True)
    payment_status = models.SmallIntegerField(verbose_name='领取状态', help_text='领取状态', choices=PAYMENT_STATUS_CHOICES, default=1)
    nonce_str = models.CharField(verbose_name=32, max_length=32)
    merchant_user = models.ForeignKey('merchants.MerchantUser', verbose_name='领取用户', on_delete=models.SET_NULL, null=True, blank=True)
    activity = models.ForeignKey('encourage.EncourageActivity', verbose_name='录入文件', on_delete=models.CASCADE)
    level = models.ForeignKey('users.Level', verbose_name='层级', on_delete=models.SET_NULL, null=True, blank=True)
    return_msg = models.TextField(null=True, blank=True)
    encouragemerchant_id = models.BigIntegerField( verbose_name='所属商户',  null=True, blank=True)
    # encouragemerchant = models.ForeignKey('merchants.EncourageMerchant', verbose_name='所属商户', on_delete=models.SET_NULL, null=True, blank=True)
    account = models.CharField(verbose_name='参与方的唯一标识', max_length=64, null=True, blank=True)
    name = models.CharField(verbose_name='参与方的唯一标识', max_length=128, null=True, blank=True)
    payment_type = models.SmallIntegerField(verbose_name='派发平台', choices=PAYMENT_TYPE_CHOICES, null=True, blank=True)
    pay_way = models.SmallIntegerField(verbose_name='派发平台', choices=PAY_WAY_CHOICES, default=1, blank=True)
    destroy_user = models.ForeignKey('users.User', verbose_name='操作人', on_delete=models.SET_NULL, null=True, blank=True)
    channel = models.ForeignKey('activities.Channel', verbose_name='派发平台', on_delete=models.SET_NULL, null=True, blank=True)
    pay_order_no = models.CharField(verbose_name='记账本id', max_length=64, null=True, blank=True)
    label = models.SmallIntegerField(verbose_name='标签', null=True, blank=True)

    class Meta:
        db_table = 'tb_m_encourage_draw'
        verbose_name = '鼓励金'
        verbose_name_plural = verbose_name




class EncourageDrawDataKeguan(models.Model):
    '''推送客管系统数据'''

    PUST_STATUS_CHOICES = (
        (1, '成功'),
        (2, '失败')
    )

    encouragedraw = models.OneToOneField('encourage.EncourageDraw', verbose_name='派发数据', on_delete=models.CASCADE)
    push_status = models.SmallIntegerField(verbose_name='推送状态', choices=PUST_STATUS_CHOICES, default=1)
    push_time = models.DateTimeField(verbose_name='推送时间')
    return_msg = models.TextField(null=True, blank=True)

    class Meta:
        db_table = 'tb_encourage_data_keguan'
        verbose_name = '鼓励金-推送客管系统数据'
        verbose_name_plural = verbose_name


class EncourageKeGuanLog(models.Model):
    #鼓励金-存量活动客管
    PUST_STATUS_CHOICES = (
        (1, '成功'),
        (2, '失败')
    )

    activity = models.OneToOneField('encourage.EncourageActivity', verbose_name='活动id', on_delete=models.CASCADE)
    push_status = models.SmallIntegerField(verbose_name='推送状态', choices=PUST_STATUS_CHOICES, default=1)
    push_time = models.DateTimeField(verbose_name='推送时间')
    return_msg = models.TextField(null=True, blank=True)
    class Meta:
        db_table = 'tb_encourage_data_keguan_log'
        verbose_name = "鼓励金-存量活动客管记录"
        verbose_name_plural = verbose_name

